##=============================================================================
## Appendix: Figure 24
##=============================================================================

##-----------------
# clear environment
rm(list=ls())
options(stringsAsFactors = FALSE, scipen = 999)
# source("R/functions.R")

seed <- sample.int(.Machine$integer.max, 1)
set.seed(seed)

ipak <- function(pkg){new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if(length(new.pkg)) install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}

packages <- c("tidyverse", "sjPlot", "lme4")

ipak(packages)

##---------
# Load data
#setwd("/Users/austinknuppe/Library/CloudStorage/Dropbox/Ukraine2022WartimeSurvey/Paper_peace/final_version_oct_2024/replication-scripts")
load("clean_ukraine_data.RData")

dat1 <- dat %>% 
  filter(wave == 0) %>%
  mutate(treated2 = factor(treated, labels = c("Control", "Survival Prime", 
                                               "Injustice Prime"))) 

# The effects of experimental primes on Save Lives (ordinal)
fit <- lmer(save_lives_z ~ 1 + survival_mindset + treated2 + 
               survival_mindset:treated + (1 + survival_mindset | adm2_pcode), 
             data = dat1)

sjPlot::tab_model(fit)

sjPlot::plot_model(fit, 
                   type = "pred", 
                   terms = c("survival_mindset", "treated2")) +
  labs(y = "Predicted Probability of Save Lives (z-std)", 
       x = "Survival Mindset",
       title = "",
       color = "Treatment") +
  theme(legend.position = "bottom",
        legend.direction = "horizontal",
        panel.spacing = unit(0.1, "lines"),
        strip.text.x = element_text(size = 18)) +
  guides(color = guide_legend(override.aes = list(fill = NA))) +
  ggtitle("Wave I: Priming Experiment (Control and Two Vignettes)") +
  hrbrthemes::theme_ipsum(axis_title_size = 18, base_size = 18, 
                          caption_size = 18, plot_title_size = 24) +
  theme(legend.position = "bottom",
        legend.direction = "horizontal",
        panel.spacing = unit(0.1, "lines"),
        strip.text.x = element_text(size = 18)) +
  guides(color=guide_legend(override.aes=list(fill=NA)))

rm(list = ls())
##=============================================================================
## End of File
##=============================================================================